from flask import render_template
from app.index import index
from app.models import Post
from flask_login import login_required


@index.route('/login', methods=['GET', 'POST'])
def index_login():
    return render_template('login.html')


@index.route('/', methods=['GET'])
@login_required
def index_index():
    # request.args get
    # request.form post
    # request.values get&&post
    return render_template('index.html')


@index.route('/post/<int:icd>', methods=['GET'])
@login_required
def index_post(icd):
    post = Post.query.filter_by(id=icd).first_or_404()
    if post.cover == '':
        post.cover = 'http://placehold.it/900x300'

    return render_template('post.html', post=post)
